﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EFCTP.DBContext;
using System.Xml;
using System.Xml.Serialization;
using EFCTP.Entity;

namespace DBReady
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //using (XmlReader reader = XmlReader.Create("product.xml"))
                //{
                //    XmlSerializer serializer = new XmlSerializer(typeof(Products));
                //    Products dd = (Products)serializer.Deserialize(reader);

                //    foreach (var item in dd.ProductList)
                //    {
                //        IndustryContext.db.Products.Add(item);
                //    }
                //    IndustryContext.db.SaveChanges();
                //}

                //Industry industry = IndustryContext.db.Industries.Find("10101020");
                //foreach (var item in industry.SubIndustries)
                //{
                //    Console.WriteLine("Code:{0}\tName:{1}\tParentCode:{2}", item.Code, item.NamePY, item.ParentIndustry.Code);
                //}
                //foreach (var item in industry.Products)
                //{
                //    Console.WriteLine();
                //}
                //Console.ReadKey();

                //using (var ctx = new IndustryContext("EFCTP"))
                //{
                //    Industry i = new Industry
                //    {
                //        Code = "AA",
                //        Name = "AA"
                //    };
                //    ctx.Industries.Add(i);
                //    ctx.SaveChanges();
                //}
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadKey();
            }
        }
    }
    [Serializable]
    public class Industries
    {
        [XmlElement("Industry")]
        public List<Industry> IndustryList { set; get; }
    }
    [Serializable]
    public class Products
    {
        [XmlElement("Product")]
        public List<Product> ProductList { set; get; }
    }
}
